<?php



namespace App\Model;

use App\Helpers\Helper;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

/**
 * 动态评论
 */
class TaskProgressDay extends Model
{
    protected $table = 'task_progress_days';

    protected $fillable = [
        "user_id", "task_id", "task_total", "created_at", "updated_at",
    ];


    public static function addRecord($user_id, $task_id,$task_total)
    {
        $first = self::where(['user_id'=>$user_id,'task_id'=>$task_id])->where('created_at','>=',date('Y-m-d'))->first();
        if(empty($first)){
            self::create([
                'user_id' => $user_id,
                'task_id' => $task_id,
                'task_total' => Db::raw($task_total)
            ]);
        }else{
            self::where('id',$first['id'])->update([
                'task_total' => Db::raw($task_total)
            ]);
        }
    }
}
